﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

using PRET.ReportDataDefine.UIData;
using PRET.ReportControlLib.ServiceReference;

namespace PRET.ReportControlLib.ReportView
{
    public partial class TVControlView : UserControl
    {
        private PRETWebServiceClient adapter = null;

        public TVControlView()
        {
            InitializeComponent();
            adapter = new PRETWebServiceClient();
        }

        private void saveBtn_Click(object sender, EventArgs e)
        {
            try
            {
                if (this.adapter == null)
                {
                    MessageBox.Show("TVControlView没有初始化Server Adapter!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                TVControlInfo info = new TVControlInfo();
                info.Message = this.messBox.Text;
                info.Time = int.Parse(this.timeBox.Text);
                info.FontSize = int.Parse(this.fontSizeTextBox.Text);
                // 从后台获取高低柜状态列表
                this.adapter.SaveTVControlInfo(info);
                MessageBox.Show("保存成功");
            }
            catch (Exception ex)
            {
                string msg = string.Format("TVControlView.TVControlView_Load() Failed: {0}.\r\nDetail: {1}", ex.Message, ex.StackTrace);
                MessageBox.Show(msg, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private void TVControlView_Load(object sender, EventArgs e)
        {
            try
            {
                if (this.adapter == null)
                {
                    MessageBox.Show("TVControlView没有初始化Server Adapter!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                this.messBox.Text = "";
                this.timeBox.Text = "";
                // 从后台获取高低柜状态列表
                TVControlInfo info = this.adapter.GetTVControlInfo();
                if (info != null)
                {
                    this.messBox.Text = info.Message;
                    this.timeBox.Text = Convert.ToString(info.Time);
                    this.fontSizeTextBox.Text = Convert.ToString(info.FontSize);
                }
            }
            catch (Exception ex)
            {
                string msg = string.Format("TVControlView.TVControlView_Load() Failed: {0}.\r\nDetail: {1}", ex.Message, ex.StackTrace);
                MessageBox.Show(msg, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
    }
}
